from django.test import TestCase

# Create your tests here.
from PIL import Image,ImageDraw,ImageFont
import random
import string
# 生成画布
image = Image.new("RGB",(180,50),"yellow")
# 创建一个画笔 来绘画
draw = ImageDraw.Draw(image)
#创建一个图片字体

font = ImageFont.truetype("simsun.ttc",size=30)

# 生成一个随机6位字符串
r = random.sample(string.digits+string.ascii_letters,6)

# 列表拼接成字符串
words = "".join(r)


# 绘制一个字符串到画布上
draw.text((50,20),text=words,fill="red",font=font)

# 显示
# image.show()


image.save(open("/uploads/static","wb"),"png")